home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / amiga-e / tools / brush2e.e < prev   
Text File  |  1999-09-13  |  7KB  |  165 lines

  1. /*
  2. ** This little program can be used to convert an ILBM brush
  3. ** to something that MUI's Bodychunk class can understand.
  4. ** For easy useage, an emodule-source is generated.
  5. **
  6. ** This tool is written by Jan Hendrik Schulz
  7. ** It is based on brush2c by Stefan Stuntz
  8. **
  9. */
  10.  
  11. OPT PREPROCESS
  12.  
  13. MODULE 'exec/types'
  14. MODULE 'libraries/iffparse'
  15. MODULE 'datatypes/pictureclass'
  16. MODULE 'graphics/gfx'
  17. MODULE 'iffparse'
  18.  
  19.  
  20. #define to32(c) (Shl(c,24) OR Shl(c,16) OR Shl(c,8) OR c)
  21.  
  22.  
  23. PROC main()
  24.  
  25.   DEF name[100]:STRING,uname[50]:STRING,c
  26.   DEF iff:PTR TO iffhandle
  27.   DEF cn:PTR TO contextnode, cn2:PTR TO contextnode
  28.   DEF sp:PTR TO storedproperty
  29.   DEF bmhd:PTR TO bitmapheader
  30.   DEF body,size,i,cols
  31.   DEF myargs:PTR TO LONG,rdargs
  32.   DEF buf[200]:STRING,colors=FALSE
  33.   DEF outfile
  34.  
  35.   myargs:=[0,0,0]
  36.   IF (rdargs:=ReadArgs('ILBMFILE/A,EMODSRC/A,NOHEADER/S',myargs,NIL))=NIL
  37.     WriteF('Bad Args!\n')
  38.     RETURN 20
  39.   ENDIF
  40.  
  41.   c:=myargs[0]
  42.   IF (i:=InStr(c,':'))<>-1 THEN c:=c+i+1
  43.   WHILE (i:=InStr(c,'/'))<>-1 DO c:=c+i+1
  44.   StrCopy(name,c)
  45.   IF (c:=InStr(name,'.'))<>-1 
  46.     name[c]:=0
  47.     SetStr(name,StrLen(name))
  48.   ENDIF
  49.   StrCopy(uname,name)
  50.   UpperStr(uname)
  51.   IF (name[]>="a") AND (name[]<="z") THEN name[]:=name[]-32
  52.  
  53.   IF iffparsebase:=OpenLibrary('iffparse.library',36)
  54.     IF outfile:=Open(myargs[1],NEWFILE)
  55.       IF iff:=AllocIFF()
  56.         iff.stream:=Open(myargs[0],OLDFILE)
  57.         IF iff.stream
  58.           InitIFFasDOS(iff)
  59.           IF OpenIFF(iff,IFFF_READ)=0
  60.             IF ParseIFF(iff,IFFPARSE_STEP)=0
  61.               IF (cn:=CurrentChunk(iff)) AND (cn.id=ID_FORM)
  62.                 IF cn.type=ID_ILBM
  63.                   IF (PropChunk(iff,ID_ILBM,ID_BMHD) OR
  64.                       PropChunk(iff,ID_ILBM,ID_CMAP) OR
  65.                       StopChunk(iff,ID_ILBM,ID_BODY) OR
  66.                       StopOnExit(iff,ID_ILBM,ID_FORM) OR
  67.                       ParseIFF(iff,IFFPARSE_SCAN))=0
  68.  
  69.                     Fputs(outfile,'-> EModule with imagedatas for MUI - generated by brush2e.\n\n')
  70.                     Fputs(outfile,'OPT MODULE\nOPT EXPORT\nOPT PREPROCESS\n\n')
  71.                     IF Not(myargs[2])
  72.                       Fputs(outfile,'MODULE \adatatypes/pictureclass\a\n')
  73.                     ENDIF
  74.                     Fputs(outfile,'MODULE \amuimaster\a, \alibraries/mui\a\n')
  75.                     Fputs(outfile,'MODULE \autility/tagitem\a\n\n')
  76.                   
  77.                     IF sp:=FindProp(iff,ID_ILBM,ID_BMHD)
  78.                       bmhd := sp.data
  79.  
  80.                       IF (bmhd.compression=CMPNONE) OR (bmhd.compression=CMPBYTERUN1)
  81.                         cn2:=CurrentChunk(iff)
  82.                         size := cn2.size
  83.  
  84.                         IF body:=New(size)
  85.                           IF ReadChunkBytes(iff,body,size)=size
  86.                             PrintF('Width \d Height \d Depth \d - converting...\n',bmhd.width,bmhd.height,bmhd.depth)
  87.  
  88.                             StringF(buf,'CONST IMG_\s_WIDTH       = \d[3]\n',uname,bmhd.width)
  89.                             Fputs(outfile,buf)
  90.                             StringF(buf,'CONST IMG_\s_HEIGHT      = \d[3]\n',uname,bmhd.height)
  91.                             Fputs(outfile,buf)
  92.                             StringF(buf,'CONST IMG_\s_DEPTH       = \d[3]\n',uname,bmhd.depth)
  93.                             Fputs(outfile,buf)
  94.                             StringF(buf,'CONST IMG_\s_COMPRESSION = \d[3]\n',uname,bmhd.compression)
  95.                             Fputs(outfile,buf)
  96.                             StringF(buf,'CONST IMG_\s_MASKING     = \d[3]\n\n',uname,bmhd.masking)
  97.                             Fputs(outfile,buf)
  98.  
  99.                             IF Not(myargs[2])
  100.                               StringF(buf,'PROC img\sHeader() IS ',name)
  101.                               Fputs(outfile,buf)
  102.                               StringF(buf,'[\d,\d,\d,\d,\d,\d,\d,0,\d,\d,\d,\d,\d]:bitmapheader\n\n',bmhd.width,bmhd.height,bmhd.left,bmhd.top,bmhd.depth,bmhd.masking,bmhd.compression,bmhd.transparent,bmhd.xaspect,bmhd.yaspect,bmhd.pagewidth,bmhd.pageheight)
  103.                               Fputs(outfile,buf)
  104.                             ENDIF
  105.  
  106.                             StringF(buf,'PROC img\sBody() IS\n [',name)
  107.                             Fputs(outfile,buf)
  108.                             FOR i:=0 TO size-2
  109.                               StringF(buf,'$\z\h[2],',body[i])
  110.                               Fputs(outfile,buf)
  111.                               IF Mod(i+1,15)=0 THEN Fputs(outfile,'\n  ')
  112.                             ENDFOR
  113.                             StringF(buf,'$\z\h[2]]:CHAR\n\n',body[size-1])
  114.                             Fputs(outfile,buf)
  115.                           ENDIF
  116.                           Dispose(body)
  117.                         ENDIF
  118.                       ENDIF
  119.                     ENDIF
  120.  
  121.                     IF sp:=FindProp(iff,ID_ILBM,ID_CMAP)
  122.                       cols := sp.data
  123.  
  124.                       StringF(buf,'PROC img\sColors() IS\n [',name)
  125.                       Fputs(outfile,buf)
  126.                       FOR i:=0 TO sp.size-4 STEP 3
  127.                         StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8],\n  ',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
  128.                         Fputs(outfile,buf)
  129.                       ENDFOR
  130.                       StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8]]\n\n',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
  131.                       Fputs(outfile,buf)
  132.                       colors:=TRUE
  133.                     ENDIF
  134.                     
  135.                     StringF(buf,'PROC img\sObject() IS\n  BodychunkObject,\n',name); Fputs(outfile,buf)
  136.                     StringF(buf,'    MUIA_Bodychunk_Body,        img\sBody(),\n',name); Fputs(outfile,buf)
  137.                     StringF(buf,'    MUIA_Bodychunk_Masking,     IMG_\s_MASKING,\n',uname); Fputs(outfile,buf)
  138.                     StringF(buf,'    MUIA_Bodychunk_Compression, IMG_\s_COMPRESSION,\n',uname); Fputs(outfile,buf)
  139.                     StringF(buf,'    MUIA_Bodychunk_Depth,       IMG_\s_DEPTH,\n',uname); Fputs(outfile,buf)
  140.                     StringF(buf,'    MUIA_Bitmap_Height,         IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
  141.                     StringF(buf,'    MUIA_Bitmap_Width,          IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
  142.                     StringF(buf,'    MUIA_FixHeight,             IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
  143.                     StringF(buf,'    MUIA_FixWidth,              IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
  144.                     IF colors
  145.                       StringF(buf,'    MUIA_Bitmap_SourceColors,   img\sColors(),\n',name); Fputs(outfile,buf)
  146.                     ENDIF
  147.                     Fputs(outfile,'  End\n\n')
  148.                     
  149.                   ENDIF
  150.                 ENDIF
  151.               ENDIF
  152.             ENDIF
  153.             CloseIFF(iff)
  154.           ENDIF
  155.           Close(iff.stream)
  156.         ENDIF
  157.         FreeIFF(iff)
  158.       ENDIF
  159.       Close(outfile)
  160.     ENDIF
  161.     CloseLibrary(iffparsebase)
  162.   ENDIF
  163.   FreeArgs(rdargs)
  164. ENDPROC 0
  165.